﻿<UserControl x:Class="GEPL.Views.Workspace"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:dd="clr-namespace:GongSolutions.Wpf.DragDrop;assembly=GongSolutions.Wpf.DragDrop"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:p="clr-namespace:GEPL.Properties"
             xmlns:vm="clr-namespace:GEPL.ViewModels"
             xmlns:converters="clr-namespace:GEPL.Converters"
             mc:Ignorable="d"
             d:DesignHeight="300" d:DesignWidth="300" d:DataContext="{d:DesignInstance vm:WorkspaceViewModel}">
    <UserControl.Resources>
        <converters:ReverseBooleanConverter x:Key="ReverseBooleanConverter" />
    </UserControl.Resources>
    <UserControl.InputBindings>
        <KeyBinding Key="Delete" Command="{Binding RemoveElementCommand}" />
    </UserControl.InputBindings>
    <DockPanel LastChildFill="True"
               IsEnabled="{Binding Project.IsExecuted, Converter={StaticResource ReverseBooleanConverter}}">
        <StatusBar DockPanel.Dock="Top"
                   Background="#FFE6E6E6"
                   Height="30">
            <StatusBarItem Content="{x:Static p:Resources.Labels_Workspace}" />
            <StatusBarItem>
                <Button Content="{x:Static p:Resources.Workspace_RemoveElement}"
                        Command="{Binding RemoveElementCommand}" />
            </StatusBarItem>
        </StatusBar>
        <ListView ItemsSource="{Binding Project.Elements}"
                  SelectedItem="{Binding SelectedElement, Mode=OneWayToSource}"
                  dd:DragDrop.IsDragSource="True"
                  dd:DragDrop.IsDropTarget="True"
                  dd:DragDrop.DropHandler="{Binding}"
                  AllowDrop="True"
                  Background="#FFE6E6E6"
                  BorderThickness="0"
                  SelectionMode="Single">
            <ListView.ItemsPanel>
                <ItemsPanelTemplate>
                    <WrapPanel Width="{Binding (FrameworkElement.ActualWidth), RelativeSource={RelativeSource AncestorType=ScrollContentPresenter}}"
                               ItemWidth="{Binding (ListView.View).ItemWidth, RelativeSource={RelativeSource AncestorType=ListView}}"
                               MinWidth="{Binding ItemWidth, RelativeSource={RelativeSource Self}}"
                               ItemHeight="{Binding (ListView.View).ItemHeight, RelativeSource={RelativeSource AncestorType=ListView}}" />
                </ItemsPanelTemplate>
            </ListView.ItemsPanel>
            <ListView.ItemTemplate>
                <DataTemplate>
                    <DockPanel LastChildFill="True"
                               Background="#33FFFFFF">
                        <Grid DockPanel.Dock="Top"
                              Margin="5,5,5,0">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="*" />
                            </Grid.ColumnDefinitions>
                            <TextBlock Grid.Column="0"
                                       Text="&#x21C9;"
                                       FontSize="18"
                                       VerticalAlignment="Center"
                                       Margin="0,0,5,0" />
                            <TextBlock Text="{Binding ActualElement.ElementName}"
                                       Grid.Column="1"
                                       HorizontalAlignment="Center"
                                       FontSize="14"
                                       VerticalAlignment="Center" />
                        </Grid>
                        <ContentControl Content="{Binding UserControlInstance}"
                                        Margin="5"
                                        MaxHeight="200"
                                        MaxWidth="200" />
                    </DockPanel>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </DockPanel>
</UserControl>